package com.arelikebrothers.demo.kafka.stream;

import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;

import java.util.HashMap;

/**
 * Created by lennon on 16/07/2017.
 */
public class DemoSerdes extends Serdes {

    public static <T> Serde<T> Json(Class<T> type) {
        JsonDeserializer<T> deserializer = new JsonDeserializer<>();
        deserializer.configure(new HashMap<String, Class<T>>() {{
            put(JsonDeserializer.DESERIALIZER_KEY, type);
        }}, false);

        JsonSerializer<T> serializer = new JsonSerializer<>();

        Serde<T> serde = serdeFrom(serializer, deserializer);

        return serde;
    }

    public static <T> Serde Window(Serde<T> innerSerde)
    {
        WindowedSerde<T> windowedSerde = new WindowedSerde<>(innerSerde);
        return windowedSerde;
    }


}
